unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ConnectButton: TButton;
    ShowWindowButton: TButton;
    HideWindowButton: TButton;
    DisconnectButton: TButton;
    procedure ConnectButtonClick(Sender: TObject);
    procedure DisconnectButtonClick(Sender: TObject);
    procedure ShowWindowButtonClick(Sender: TObject);
    procedure HideWindowButtonClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
  ComObj;

var _H2ViewerSvr: Variant;


procedure TForm1.ConnectButtonClick(Sender: TObject);
begin
  try
    _H2ViewerSvr := CreateOleObject('H2Viewer.h2vmain');
    ShowMessage('Connected to H2Viewer OK');
  except
    ShowMessage('Connected to H2Viewer ** Failed **'#13'Try running H2Viewer.exe once to register it');
    VarClear(_H2ViewerSvr);
  end;
end;

procedure TForm1.DisconnectButtonClick(Sender: TObject);
begin
  if (VarType(_H2ViewerSvr) in [varEmpty, varNull]) then Exit;
  VarClear(_H2ViewerSvr);
end;

procedure TForm1.ShowWindowButtonClick(Sender: TObject);
begin
  if (VarType(_H2ViewerSvr) in [varEmpty, varNull]) then Exit;
 _H2ViewerSvr.ShowWindow := 1;
end;

procedure TForm1.HideWindowButtonClick(Sender: TObject);
begin
  if (VarType(_H2ViewerSvr) in [varEmpty, varNull]) then Exit;
 _H2ViewerSvr.ShowWindow := 0;
end;

end.
